﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xrm.Sdk;
using System.Threading;

namespace XRM.Solutions.FrameworkSample.Common
{
    public class AutoNumberGenerator : IAutoNumberGenerator
    {
        #region Properties

        protected ITracingService TracingService
        {
            get;
            private set;
        }

        #endregion

        #region Constructors

        public AutoNumberGenerator(ITracingService tracingService)
        {
            TracingService = tracingService;
        }

        #endregion

        #region IAutoNumberGenerator

        public string Generate(string entityType, string attributeName)
        {
            TracingService.Trace("Autonumber Generate Start");
            Thread.Sleep(10000);
            Random random = new Random();
            int autoNumber = random.Next(10000000, 99999999);
            TracingService.Trace("Random Generation Finished");
            return random.ToString();
        }

        #endregion
    }
}
